package com.ruoyi.quartz.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.quartz.domain.LotTicket;
import com.ruoyi.quartz.mapper.LotTicketTypeMapper;
import com.ruoyi.quartz.domain.LotTicketType;
import com.ruoyi.quartz.service.ILotTicketTypeService;

/**
 * tolTypeService业务层处理
 * 
 * @author ruoyi
 * @date 2024-10-30
 */
@Service
public class LotTicketTypeServiceImpl implements ILotTicketTypeService 
{
    @Autowired
    private LotTicketTypeMapper lotTicketTypeMapper;

    /**
     * 查询tolType
     * 
     * @param ticketTypeId tolType主键
     * @return tolType
     */
    @Override
    public LotTicketType selectLotTicketTypeByTicketTypeId(Long ticketTypeId)
    {
        return lotTicketTypeMapper.selectLotTicketTypeByTicketTypeId(ticketTypeId);
    }

    /**
     * 查询tolType列表
     * 
     * @param lotTicketType tolType
     * @return tolType
     */
    @Override
    public List<LotTicketType> selectLotTicketTypeList(LotTicketType lotTicketType)
    {
        return lotTicketTypeMapper.selectLotTicketTypeList(lotTicketType);
    }

    /**
     * 新增tolType
     * 
     * @param lotTicketType tolType
     * @return 结果
     */
    @Transactional
    @Override
    public int insertLotTicketType(LotTicketType lotTicketType)
    {
        int rows = lotTicketTypeMapper.insertLotTicketType(lotTicketType);
        insertLotTicket(lotTicketType);
        return rows;
    }

    /**
     * 修改tolType
     * 
     * @param lotTicketType tolType
     * @return 结果
     */
    @Transactional
    @Override
    public int updateLotTicketType(LotTicketType lotTicketType)
    {
        lotTicketTypeMapper.deleteLotTicketByTicketTypeId(lotTicketType.getTicketTypeId());
        insertLotTicket(lotTicketType);
        return lotTicketTypeMapper.updateLotTicketType(lotTicketType);
    }

    /**
     * 批量删除tolType
     * 
     * @param ticketTypeIds 需要删除的tolType主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteLotTicketTypeByTicketTypeIds(Long[] ticketTypeIds)
    {
        lotTicketTypeMapper.deleteLotTicketByTicketTypeIds(ticketTypeIds);
        return lotTicketTypeMapper.deleteLotTicketTypeByTicketTypeIds(ticketTypeIds);
    }

    /**
     * 删除tolType信息
     * 
     * @param ticketTypeId tolType主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteLotTicketTypeByTicketTypeId(Long ticketTypeId)
    {
        lotTicketTypeMapper.deleteLotTicketByTicketTypeId(ticketTypeId);
        return lotTicketTypeMapper.deleteLotTicketTypeByTicketTypeId(ticketTypeId);
    }

    /**
     * 新增彩票信息信息
     * 
     * @param lotTicketType tolType对象
     */
    public void insertLotTicket(LotTicketType lotTicketType)
    {
        List<LotTicket> lotTicketList = lotTicketType.getLotTicketList();
        Long ticketTypeId = lotTicketType.getTicketTypeId();
        if (StringUtils.isNotNull(lotTicketList))
        {
            List<LotTicket> list = new ArrayList<LotTicket>();
            for (LotTicket lotTicket : lotTicketList)
            {
                lotTicket.setTicketTypeId(ticketTypeId);
                list.add(lotTicket);
            }
            if (list.size() > 0)
            {
                lotTicketTypeMapper.batchLotTicket(list);
            }
        }
    }
}
